package org.wattdepot.cli;

/**
 * Manipulate the user's input and return the arguments.
 * @author wattdepot-cli-ewalu
 *
 */
public class StringExtraction implements StringInterface {
  /**Holds the argument to extract data from. */
  private String command;
  
  /**
   * Constructor that create a new StringExtraction object.
   * @param text holds the user's input
   */
  public StringExtraction(String text) {
    command = text;
  }
  
  /**
   * Break down the user's input into workable arguments.
   * @return parsed string to work with argument(s) only
   */
  public String parse() {
    String literal = "";
    String holder[] = command.split(" ");
    if (holder.length == 1) {
      literal = holder[0];
    }
    else if (holder.length == 2) {
      if ((!holder[1].equalsIgnoreCase("help")) && 
        (!holder[1].equalsIgnoreCase("quit"))) {
        literal = holder[1];
      }
    }
    else if (holder.length == 4) {
      literal = holder[1] + " " + holder[3];
    }
    else if (holder.length == 5) {
      literal = holder[1] + " " + holder[2] + " " + holder[4];
    }
    else if (holder.length == 8) {
      literal = holder[1] + " " + holder[2] + " " + holder[3] + " " + 
      holder[5] + " " + holder[7];
    }
    else if (holder.length == 9) {
      if (holder[0].equals("total")) {
        literal = null;
      }
      else {
        literal = holder[1] + " " + holder[2] + " " + holder[4] + " " + 
        holder[6] + " " + holder[8];
      }
    }
    else if (holder.length == 10) {
      if (holder[0].compareTo("chart") == 0) {
        literal = holder[2] + " " + holder[3] + " " + holder[4] + " " + holder[5]
          + " " + holder[7] + " " + holder[9];
      }
    }
    else {
      literal = null;
    }
    return literal;
  }
  
  /**
   * Return the entire user input.
   * @return command user's input
   */
  public String getInput() {
    return command;
  }
}
